package com.cxyzy.rxtimer;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.jakewharton.rxbinding2.view.RxView;

import java.util.concurrent.TimeUnit;

import io.reactivex.functions.Consumer;

public class MainActivity extends AppCompatActivity {
    private RxTimer rxTimer = new RxTimer();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initListeners();
    }

    private void initListeners() {
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rxTimer.timer(1000, number -> Toast.makeText(MainActivity.this, "延迟1秒显示的toast", Toast.LENGTH_SHORT).show());
            }
        });
    }

    @Override
    protected void onDestroy(){
        //取消定时器
        rxTimer.cancel();
        super.onDestroy();
    }
}
